import sys
import os
import time
import math
BASE_PATH = os.path.dirname(
    os.path.dirname(os.path.abspath(__file__))
)
sys.path.insert(0,BASE_PATH)
from bin import get_Webdriver

class Data_Market:
    def __init__(self):
        self.driver = get_Webdriver.Get_Webdriver().driver

    def jumptoDataMarketpage(self):
        """进入数据集市"""
        self.driver.click("link_text=>数据集市")

    def clickInfodatabyName(self, name):
        """数据集市页面点击咨询数据中某个项目，根据text"""
        self.driver.click("link_text=>{}".format(name))

    def clickInfodata(self, id):
        """数据集市页面点击咨询数据中某个项目，根据id"""
        self.driver.click("id=>data_{}".format(id))

    def checkWhichInfopage(self):
        """检查资讯数据页面，媒体类型位置选中哪项value"""
        value_list = self.getvaluesInfopage()
        bechecklist = []
        for i in value_list:
            if self.driver.if_select('css=>input[value="{}"][name="filter_media"]'.format(i)):
                bechecklist.append(i)
        return bechecklist

    def getvaluesInfopage(self):
        """资讯数据页面，返回媒体类型values"""
        value_list = self.driver.get_attributes("css=>input[name='filter_media']", "value")
        return value_list

    def clickAccountdata(self, id):
        """数据集市页面点击账号数据中某个项目，根据id"""
        self.driver.click("css=>#accountData_{}".format(id))

    def getvaluesAccountpage(self):
        """账号数据页面，返回账号类型values"""
        value_list = self.driver.get_attributes("css=>input[name='account_type']", "value")
        return value_list

    def checkWhichAccountpage(self):
        """检查账号数据页面，账号类型位置选中哪项value"""
        value_list = self.getvaluesAccountpage()
        bechecklist = []
        for i in value_list:
            if self.driver.if_select('css=>input[value="{}"][name="account_type"]'.format(i)):
                bechecklist.append(i)
        return bechecklist

    def clickCompanydata(self, id):
        """数据集市页面点击账号数据中某个项目，根据id"""
        self.driver.click("css=>#companyData_{}".format(id))

    def clickBusinessdata(self, id):
        """数据集市页面点击账号数据中某个项目，根据id"""
        self.driver.click("css=>#businessData_{}".format(id))

    def clickBusinessdataNmae(self, name):
        """数据集市页面点击账号数据中某个项目，根据id"""
        self.driver.click("link_text=>{}".format(name))

    def getactiveLabel(self):
        """获取页面上被激活的标签id"""
        active_id = self.driver.get_attributes("css=>ul[class='nav nav-tabs nav-datatitle']>li[class='active']>a", "id")
        return active_id

    def clickAbroaddata(self, id):
        """数据集市页面点击账号数据中某个项目，根据id"""
        self.driver.click('''css=>a[onclick="getAbroad('{}')"]'''.format(id))


    def getvaluesAbroadpage(self):
        """账号数据页面，返回账号类型values"""
        value_list = self.driver.get_attributes("css=>input[name='filter_type']", "value")
        return value_list

    def checkWhichAbroadpage(self):
        """检查账号数据页面，账号类型位置选中哪项value"""
        value_list = self.getvaluesAbroadpage()
        bechecklist = []
        for i in value_list:
            if self.driver.if_select('css=>input[value="{}"][name="filter_type"]'.format(i)):
                bechecklist.append(i)
        return bechecklist
